Tutorial #1: Goto previous page action We will create a very simple but useful action which uses a single JavaScript function and requires no parameter inputs. This is the simplest kind of action and can be repeated with any type of JavaScript function. We will use history.back(), a built-in JavaScript method which causes the previous page in the browser to load when the action is triggered. 1 First, you need to duplicate an existing action file and rename it. Adobe GoLive includes a template folder with a blank action ready to duplicate. Also, you can create a new subfolder in the actions folder and call it "test" or some other unique name. (With Adobe GoLive version 3.0 and earlier, you can just put the file in with the rest of the actions in the actions folder.) With this example you can duplicate the alert.action file into the appropriate folder and rename it PreviousPage.action. You can change the icon later. Open the file in Adobe GoLive to begin editing it. 2 Give the action a new Title, such as "Go Previous URL Action." Remember the title can be anything, it will only appear in the layout view. 3 Define the action class. Click on the <csactionclass> tag to bring up the Inspector and view its attributes. The first attribute is NAME. This is the name that will appear in the Adobe GoLive Action pop-up menu. Use "Go Last Page." At this point if you exit from and restart Adobe GoLive you will have a new action entitled "Go Last Page" in the actions menu. 4 The next attribute is FUNCTION. This value must correspond to the name of the function in your JavaScript code. Since you haven't written the code yet you can make up a function name now, as long as you repeat it later in the code. Use "CSGoBack1." You don't need to use the first two letters CS, the included actions only use this to make the function names more unique to avoid the possibility of creating duplicate function names. 5 The final two attributes are the Netscape and Internet Explorer supported browser versions. If you're creating your own actions, you'll have to determine for yourself which browsers will support the code you are using. In the case of this action, the history.back() method is supported by Netscape 3 browsers and above and Internet Explorer 3 browsers and above (you'll have to determine this on your own by testing your code in each browser). Enter the number 3 into each field. Now you have defined your action class object. Important: At this basic level, the action will not perform any browser checking and may produce errors with earlier unsupported browsers. This is dependent on the behavior of the JavaScript code itself. It is possible to do browser checking, but this requires extra coding and can be accomplished with the inclusion of an if() statement at the beginning of the script which checks the User Agent or appVersion of the browser. It's good practice to design your actions so they are well behaved in all browsers. In other words, where the script doesn't work, it should be ignored by the browser and not produce any errors. Since this script won't require any user input, it won't need a <csactionparam> tag. Delete this tag from the page. Now you have only opening and closing <csactionclass> tags, the minimum required for an action file. 6 Now it's time to put in your JavaScript code. You do this by double-clicking on the code icon to bring up the Script Editor. Replace the existing code with the following: function CSGoBack1() { history.back() } With all Adobe GoLive actions, you embed your JavaScript code between the two curly brackets of the initial function. In this case the initial function is: CSGoBack1() {} This code is an example of a very simple script which uses no arguments, thus it requires no parameter values. For info on how parameters work see the next example. 7 The last step in creating this action is to modify the layout grid for the dialog box content. Since there are no input fields you can delete the "msg" field and change the "message" field to an Info Text type using the pull-down menu in the Inspector or Actions palette. Now you can include a message for the user by typing it into the name field, something like "Use this action to return to the previous URL." After you save your action, you'll be ready to apply it in Adobe GoLive. Remember you need to restart the application in order for your new action to load into Adobe GoLive and appear in the actions menu. If on restarting the application, Adobe GoLive crashes or you get an error message, it means there's an error in your action file. Just remove the action from the folder and restart. Adobe GoLive will also generate an error message and a log file listing the offending action. Creating Actions > Action tutorials > Tutorial #1: Goto previous page action |